package function;

public class Result<T> {

    private String msg;
    private T data;
    private boolean ok;

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isOk() {
        return ok;
    }

    public boolean isFailed() {
        return !ok;
    }

    public void setOk(boolean ok) {
        this.ok = ok;
    }

    public Result(String msg, T data, boolean ok) {
        this.msg = msg;
        this.data = data;
        this.ok = ok;
    }

    public static <T> Result<T> success(T data) {
        return new Result("ok", data, true);
    }

    public static Result success() {
        return new Result("ok", null, true);
    }

    public static Result failed(String msg) {
        return new Result(msg, null, false);
    }

    public static Result failed() {
        return new Result("failed", null, false);
    }
}